package com.empty.oredermenu.utils

import android.annotation.TargetApi
import android.app.Activity
import android.os.Build
import android.view.Window
import android.view.WindowManager

/**
 * Created by empty cup on 2017/7/10.
 */

class ToolsUtils{
    /**
     * 沉寖时状态栏
     * @param window 窗口
     * *
     * @param activity 上下文
     * *
     * @param idresouce 颜色值
     */
    fun BuildColor(window: Window, activity: Activity, idresouce: Int) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(window, true)
            val tintManager = SystemBarTintManager(activity)
            tintManager.isStatusBarTintEnabled = true
            tintManager.setNavigationBarAlpha(0.3f)
            tintManager.setStatusBarTintResource(idresouce)//通知栏所需颜色
        }
    }

    @TargetApi(19)
    fun setTranslucentStatus(window: Window, on: Boolean) {
        //        Window win = window;
        val winParams = window.attributes
        val bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
        if (on) {
            winParams.flags = winParams.flags or bits
        } else {
            winParams.flags = winParams.flags and bits.inv()
        }
        window.attributes = winParams
    }
}
